package org.sunshine.dye.controller.info;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.sunshine.dye.base.Result;
import org.sunshine.dye.dto.CustomerDto;
import org.sunshine.dye.exception.BusinessException;
import org.sunshine.dye.exception.SysException;
import org.sunshine.dye.service.info.CustomerService;

@RestController
@RequestMapping("/info/customer")
public class CustomerController {
	
	@Autowired
	private CustomerService customerService;
	
	@GetMapping("/cus")	
	public Map<String,Object> cusList(CustomerDto dto){		
		
		return customerService.getCustomerList(dto);
	}
	
	@PostMapping("/cus")	
	public Result execAddCus(@RequestBody CustomerDto dto){
		customerService.addCustomer(dto);
		return Result.success("新增客户信息成功！");
	}
	
	@PutMapping("/cus")	
	public Result execUpdCus(@RequestBody CustomerDto dto){
		customerService.updateCustomer(dto);
		return Result.success("修改客户信息成功！");
	}
	
	@DeleteMapping("/cus/{id}")	
	public Result execDelCus(@PathVariable Integer id){
		customerService.deleteCustomer(id);
		return Result.success("删除客户信息成功！");
	}
	
	@DeleteMapping("/cus")	
	public Result execDelCus(@RequestBody Integer... ids){
		try {
			customerService.deleteCustomer(ids);
			return Result.success("删除客户信息成功！");
		} catch (BusinessException e) {
			return Result.fail(e.getMessage());
		}catch (SysException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return Result.fail("系统维护中...");
		}
	}

}
